<template>

<div>
  <van-nav-bar
  title="标题"
  left-text="返回"
  right-text="按钮"
  @click-left="onClickLeft"
  @click-right="onClickRight"
/>
 <van-field
  v-model="message"
  type="textarea"
  maxlength="7"
  placeholder="请输入新的昵称"
  show-word-limit
/></div>
</template>

<script>
import { toedituserinfo } from '@/api/getverify'
import { Toast } from 'vant'
export default {
  data () {
    return {
      message: ''
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },

  created () {
    this.message = this.value
  },

  methods: {
    onClickLeft () {
      this.$emit('onclose')
    },
    async  onClickRight () {
      try {
        const res = await toedituserinfo({
          name: this.message
        })
        console.log(res)
        this.$emit('onclose')
        this.$emit('input', this.message)
        Toast('更新成功')
      } catch (error) {
        console.dir(error)
        if (error.response && error.response.status === 409) {
          Toast('昵称已存在')
          return
        }
        Toast('跟新失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
